package com.config;

import org.lucksyc.util.resultview.sprout.ResultViewProperties;
import org.lucksyc.utilindependent.resultview.core.setting.ViewSetting;
import org.lucksyc.utilindependent.resultview.seed.deal.ViewBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.util.Util;

@Configuration
public class MyConfig {
	
	@Autowired
	private ViewSetting viewSetting;
	@Autowired
	private ResultViewProperties viewProperties;
	
	@Bean
	public ViewBuilder viewBuilder() {
		viewSetting.setVersion(viewProperties.getVersion());
		viewSetting.setDefaultErrorCode(viewProperties.getDefaultErrorCode());
		viewSetting.setExplain(viewProperties.isExplain());
		// 配置JSON转换器
		viewSetting.setJsonConverter(obj->Util.toJson(obj));
		ViewBuilder builder = new ViewBuilder();
		builder.updateSetting(viewSetting);
		return builder;
	}
}
